﻿using System;
using BLL;
using BLL.Access;
using System.Data;
using DevExpress.Web;

namespace Web.Pages.YongShui._13.LAIHANGL
{
    public partial class YUETIAOZJHXX : BasePage
    {
        #region 属性
        public DataTable DataSource1
        {
            get { return ViewState["DataSource1"] as DataTable; }
            set { ViewState["DataSource1"] =value; }
        }
        public DataTable DataSource2
        {
            get { return ViewState["DataSource2"] as DataTable; }
            set { ViewState["DataSource2"] = value; }
        }
        #endregion

        #region 变量
        SpHelper _sphelper = new SpHelper();

        YS_ZW_YINGYEZBLL yyzbll = new YS_ZW_YINGYEZBLL();

        YS_YG_YONGHUXXBLL bllyhxx = new YS_YG_YONGHUXXBLL();
        #endregion

        #region 事件
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Bind();

            }
            gvJH.DataSource = DataSource1;
            gvJH.DataBind();
            GVSF.DataSource = DataSource2;
            GVSF.DataBind();
        }
        #endregion

        #region 方法
        /// <summary>
        /// 绑定数据
        /// </summary>
        private void Bind()
        {
            gvJH.SettingsPager.Mode = GridViewPagerMode.EndlessPaging;
            gvJH.SettingsPager.PageSize = 40;

            GVSF.SettingsPager.Mode = GridViewPagerMode.EndlessPaging;
            GVSF.SettingsPager.PageSize = 40;
            string yhh = "1401623";
            if (string.IsNullOrEmpty(Request["yonghuh"]))
            {
                return;
            }

            yhh = Request["yonghuh"];
            string yhwhere = string.Format(" S_YONGHUH='{0}' and I_leixing=0 and i_jlzt=0 ",yhh); ;
            DataTable yhxx = bllyhxx.SelectYS_YG_YONGHUXXesDynamic(yhwhere,"",null);
            if (yhxx != null && yhxx.Rows.Count > 0)
            {
                txtYHH.Text = yhxx.Rows[0]["S_YONGHUH"].ToString();
                txtYHM.Text = yhxx.Rows[0]["S_YONGHUM"].ToString();
            }
            else
            {
                return;
            }
            string where = string.Format(" S_YONGHUH='{0}'",yhh);
            DataSet ds = _sphelper.P_YS_LH_YONGHUYSSJCX_WHERE(where);
            DataSource1 = ds.Tables[0];
            gvJH.DataSource = DataSource1;
            gvJH.DataBind();

            DataTable dt = yyzbll.SelectYS_ZW_YINGYEZsDynamic(where, " I_Y desc,I_M desc", null);
            DataTable yyz = new DataTable();
            yyz.Columns.Add("YM");
            yyz.Columns.Add("KZJE");
            yyz.Columns.Add("SSJE");
            yyz.Columns.Add("QFTZ");
            yyz.Columns.Add("QFJE");
            if (dt != null && dt.Rows.Count > 0)
            {
                //DataRow newdr = null;
                foreach (DataRow dr in dt.Rows)
                {
                    DataRow newdr = yyz.NewRow();
                    newdr[0] = Convert.ToInt32(dr["I_Y"]) * 100 + Convert.ToInt32(dr["I_M"]);
                    newdr[1] = dr["N_JIAJIAJE"];
                    newdr[2] = dr["N_SHISHOUJE"];
                    newdr[3] = Convert.ToDouble(dr["N_JIAJIAJE"]) - Convert.ToDouble(dr["N_YINGSHOUJE"]);
                    newdr[4] = Convert.ToDouble(dr["N_YINGSHOUJE"]) - Convert.ToDouble(dr["N_SHISHOUJE"]);
                    yyz.Rows.Add(newdr);
                }
            }
            DataSource2 = yyz;
            GVSF.DataSource = DataSource2;
            GVSF.DataBind();
        }
        #endregion
    }
}